package main

import "fmt"

func main() {
	// 类型、长度、容量
	var numbers = make([]int, 3, 5)

	fmt.Printf("len=%d,cap=%d,slice=%v\n",
		len(numbers), cap(numbers), numbers)
	// 向切片中追加一个元素1, len = 4 ,[0,0,0,1],cap =5
	numbers = append(numbers, 1)
	fmt.Printf("len=%d,cap=%d,slice=%v\n",
		len(numbers), cap(numbers), numbers)
	// 向切片中追加一个元素1, len = 5 ,[0,0,0,1,2],cap =5
	numbers = append(numbers, 2)
	fmt.Printf("len=%d,cap=%d,slice=%v\n",
		len(numbers), cap(numbers), numbers)

	//当再次追加的时候 len > cap 后会触发扩容 cap=2*cap_old
	//len =6 ,cap =10 ,[0,0,0,1,2,3]
	numbers = append(numbers, 3)
	fmt.Printf("len=%d,cap=%d,slice=%v\n",
		len(numbers), cap(numbers), numbers)

}
